<template>
  <div id="boxlist" class="flex" style="flex:1; ">
    <criteria-paged :model="model" v-ref:paged>
      <criteria partial='criteria' @condition-changed='search' v-ref:cri>
        <div novalidate class="form-inline" partial>
          <div class="form-group">
            <label for="f_ajustable_name" class = "control-form">调压箱编号:</label>
            <input type="text" class="form-control" v-model="model.f_adjustable_id"
            condition="a.f_adjustable_id like '%{}%'" placeholder='调压箱编号'>
          </div>
          <div class="form-group">
            <label for="f_ajustable_name" class = "control-form">调压箱名称:</label>
            <input type="text" class="form-control" v-model="model.f_adjustable_name"
            condition="f_adjustable_name like '%{}%'" placeholder='名称'>
          </div>
          <div class="form-group">
            <label for="f_ajustable_address" class = "control-form">调压箱地址:</label>
            <input type="text" class="form-control" v-model="model.f_adjustable_address"
            condition="f_adjustable_address like '%{}%'" placeholder='地址'>
          </div>

          <div class="form-group">
            <button class="btn btn-success width-80" @click="$parent.$parent.search()" v-el:cx>查询</button>
          </div>
          <div class="form-group">
            <button class="btn btn-success width-80" @click="$parent.$parent.createNew()" v-el:cx>新建</button>
          </div>
          <div class="form-group">
            <export-excel :data="{orderitem: 'f_adjustable_id',condition: $parent.model.condition}" bean="调压箱导出" sqlurl="rs/logic/exportfile"></export-excel>
          </div>
        </div>
      </criteria>
      <data-grid :model="model" partial='list' v-ref:grid>
        <template partial='head'>
          <tr>
            <th>序号</th>
            <th>调压箱编号</th>
            <th>调压箱名称</th>
            <th>调压箱地址</th>
            <th>用户数</th>
            <th>操作</th>
          </tr>
        </template>
        <template partial='body'>
          <td style="text-align: center;">{{$index+1}}</td>
          <td>{{row.f_adjustable_id}}</td>
          <td>{{row.f_adjustable_name}}</td>
          <td>{{row.f_adjustable_address}}</td>
          <td>{{row.counts}}</td>
          <td style="text-align:center">
            <button class="btn btn-link "   v-if = "row.counts === 0" @click.stop="$parent.$parent.$parent.del(row.f_adjustable_id)"> 删除 </button>
          </td>
        </template>
      </data-grid>
  </criteria-paged>
 </div>
</template>
<script>
import { PagedList } from 'vue-client'
// import AppData from '../../../../stores/AppData'

export default {
  title: '调压箱',
  data () {
    return {
      model: new PagedList('rs/sql/adjustableboxQuery', 20)
    }
  },
  props: [],
  ready () {
    this.model.search('1=1')
  },
  methods: {
    search () {
      // this.model.search()
      this.$dispatch('search')
    },
    createNew () {
      console.log('123123')
      this.$dispatch('add')
    },
    del (id) {
      this.$showMessage('确认删除吗?', ['confirm', 'cancel']).then(
        (response) => {
          if (response === 'confirm') {
            this.$resetpost('rs/logic/deleteBox', {data: {id: id}}, {resolveMsg: '删除成功', rejectMsg: '删除失败'})
            .then((res) => { this.$dispatch('success', '调压箱删除', this.data, res) })
            .catch((error) => { this.$dispatch('error', '调压箱删除', this.data, error) })
          } else if (response === 'cancel') {
            this.$dispatch('cancel')
          }
        })
    }
  }
}
</script>
